package com.linchong.source.basic;

/**
 * @author linchong
 * @version 1.0
 * @Date: 2020-12-11 10:48
 * @Description: StringClass$String源码解析
 *
 */
public class StringClass {

	public static void compare(){
		String s1 = new String("Java");

		String s2 = s1.intern();

		String s3 = "Java";

		// 常量池没有“Java”引用，创建一个返回，false
		System.out.println(s1==s2);
		// 常量池有“Java”常量引用，返回引用  true
		System.out.println(s2==s3);

		System.out.println(s1==s3);

		//编译器优化,true
		String s4 = "Ja"+"va";
		String s5 = "Java";
		System.out.println(s4==s5);

	}
	public static void main(String[] args) {
		compare();
	}


}
